/**
 * 
 */
package com.neal.service.securities.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.neal.domain.securities.Resources;
import com.neal.repositories.securities.ResourceRepository;
import com.neal.service.securities.IResourceService;

/**
 * @author Neal
 * @version 1.0
 * @description
 */
@Service("resourceService")
@Transactional(readOnly = true)
public class ResourceServiceBean implements IResourceService {

	@Autowired
	private ResourceRepository resourceRepository;

	
	@PersistenceContext(unitName="nealJPA")
	private EntityManager em;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.neal.service.securities.IResourceService#findAllResources()
	 */
	@Override
	public List<Resources> findAllResources() {
		return resourceRepository.findAll();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.neal.service.securities.IResourceService#findAllResourcesFetchRole()
	 */
	@Override
	public List<Resources> findAllResourcesFetchRole() {
		return em.createQuery("select r from Resources r inner join fetch r.roles", Resources.class).getResultList();
	}

	public void setResourceRepository(ResourceRepository resourceRepository) {
		this.resourceRepository = resourceRepository;
	}

	public void setEm(EntityManager em) {
		this.em = em;
	}

}
